//
//  FindViewController.m
//  Home
//
//  Created by 杨泓晔 on 16/4/8.
//  Copyright © 2016年 LanJue. All rights reserved.
//

#import "FindViewController.h"
#import "YHYExpertFindViewCell.h"
#import "YHYDetailViewController.h"
#import "YHYAnimationDemo.h"
#import "WUVippViewController.h"
#import "YHYFindSearchViewController.h"
#import "AFNetworking.h"

@interface FindViewController ()<UITableViewDataSource,UITableViewDelegate,YHYAnimationDemoDelegate>
@property (nonatomic,retain)UITableView *myTableView;
@property (nonatomic,retain)WSCustomButton *singin, *SSbution;
@property (nonatomic,retain) UILabel *balabel;
@property (nonatomic,retain) NSArray *imageArray;
@property (nonatomic,retain) UIScrollView *BigScrollView;
@property (nonatomic,retain) YHYAnimationDemo *naView;

@end

@implementation FindViewController
- (void)viewWillAppear:(BOOL)animated {
    
    self.navigationController.navigationBarHidden = NO;
    self.navigationController.navigationBar.translucent = NO;
    self.tabBarController.tabBar.hidden=NO;
}

//  寻找设计师
- (void)viewDidLoad {
    [super viewDidLoad];
    [self creatView];
    [self loadData];
    self.navigationController.navigationBar.barTintColor = HEADVC;
    
     _imageArray=[NSArray arrayWithObjects:[UIImage imageNamed:@"ni"],[UIImage imageNamed:@"nn"],[UIImage imageNamed:@"wo"],[UIImage imageNamed:@"ww"],[UIImage imageNamed:@"to"],[UIImage imageNamed:@"tt"],[UIImage imageNamed:@"yo"],[UIImage imageNamed:@"yy"],[UIImage imageNamed:@"to"],[UIImage imageNamed:@"tt"], nil];
    
    self.view.backgroundColor=LV;
    
  
    //圆圈
    self.singin=[[WSCustomButton alloc]init];
    [self.singin setImage:[[UIImage imageNamed:@"QQ"]  imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] forState:UIControlStateNormal];
    self.singin.frame=CGRectMake(0, 0, 30 *AUTO_WIDTH, 30*AUTO_HEIGHT);
    [self.singin addTarget:self action:@selector(singinAction:) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem=[[UIBarButtonItem alloc]initWithCustomView:_singin];
    
    
    //100
    _balabel=[[UILabel alloc]init];
    _balabel.text=@"100";
    _balabel.textColor=[UIColor whiteColor];
    _balabel.textAlignment=NSTextAlignmentLeft;
    _balabel.font=[UIFont fontWithName:TFont size:TEXTCONTENTFONT * AUTO_WIDTH];
    [_singin addSubview:_balabel];
    [_balabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(_singin).offset(5 *AUTO_HEIGHT);
        make.left.equalTo(_singin).offset(0);
        make.size.mas_equalTo(CGSizeMake(28*AUTO_WIDTH, 20*AUTO_HEIGHT));
    }];
    
    
    //右边按钮
    self.SSbution = [WSCustomButton buttonWithType:UIButtonTypeCustom];
    self.SSbution.frame = CGRectMake(0, 0, 30, 30);
    
    [self.SSbution setImage:[[UIImage imageNamed:@"搜索"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] forState:UIControlStateNormal];
    // self.SSbution.backgroundColor = [UIColor whiteColor];
    [self.SSbution addTarget:self action:@selector(souSuo:) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:_SSbution];
    
    
}

-(void) button:(UIButton *)btn
{
    if (btn.tag == 1000) {
        self.BigScrollView.contentOffset = CGPointMake(0, 0);
    }
    
    if (btn.tag == 1001 ) {
        self.BigScrollView.contentOffset = CGPointMake(KScreenWidth, 0);
        
    }
    if (btn.tag == 1002) {
        self.BigScrollView.contentOffset = CGPointMake(KScreenWidth * 2, 0);
        
    }
    

}


- (void)creatView{
    
     _naView= [[YHYAnimationDemo alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 40 * AUTO_WIDTH)];
    _naView.delegate=self;
    [self.view addSubview:_naView];
    
    
    self.BigScrollView = [[UIScrollView alloc]init];
    [self.view addSubview:self.BigScrollView];
    self.BigScrollView.delegate = self;
    self.BigScrollView.contentSize = CGSizeMake(self.view.frame.size.width*3, 0);
    self.BigScrollView.bounces = NO;
    self.BigScrollView.pagingEnabled = YES;
    self.BigScrollView.backgroundColor =LV;
    self.BigScrollView.pagingEnabled = YES;
    [self.BigScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.view.mas_top).offset(48 *AUTO_HEIGHT);
        make.size.mas_equalTo(CGSizeMake(self.view.frame.size.width, self.view.frame.size.height-100 *AUTO_HEIGHT));
        
    }];

    
    
    
    _myTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height -100 *AUTO_HEIGHT)];
    _myTableView.backgroundColor = LV;
    _myTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    _myTableView.delegate = self;
    _myTableView.dataSource = self;
    [self.BigScrollView addSubview:_myTableView];
    
    
    
    [_myTableView registerClass:[YHYExpertFindViewCell class] forCellReuseIdentifier:@"YHYFindViewCell"];
    
    
}
#pragma mark - 请求数据
- (void)loadData{
    
//    [MHNetworkManager postReqeustWithURL:@"http://114.215.240.173/api/index.php/Home/Index/vInfo/uid/111/suid/333/tid/444" params:@{@"uid":MYUID,@"suid":self.designerUid ,@"tid":self.tastId} successBlock:^(NSDictionary *returnData) {
//        NSLog(@"uuuuu=%@",returnData);
//       
//    } failureBlock:^(NSError *error) {
//        
//    } showHUD:YES];
    
    
    NSString *url_string = [NSString stringWithFormat:@"http://api.liwushuo.com/v2/channels/118/items?ad=1&gender=1&generation=2&limit=20&offset=5"];
    
   
    
    AFHTTPRequestOperationManager* manager = [AFHTTPRequestOperationManager manager];
    
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/plain",@"text/json",@"application/json",@"text/javascript",@"text/html",nil]; //代表支持所有的接口类型
    
    [manager GET:url_string parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        NSLog(@"sssss=%@",responseObject);
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
        NSLog(@"失败==== %@",error);
        
    }];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 10;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *str = @"YHYFindViewCell";
    YHYExpertFindViewCell *cell = [tableView dequeueReusableCellWithIdentifier:str forIndexPath:indexPath];
    cell.selectionStyle=UITableViewCellSelectionStyleNone;
    
    cell.myImageView.image=[_imageArray objectAtIndex:indexPath.row];
    
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 750/3 * AUTO_HEIGHT;
}



- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
//    NSUserDefaults *user=[NSUserDefaults standardUserDefaults];
//    NSString *passWord=[user objectForKey:@"passWord"];
//    NSLog(@"pppppp=%@",passWord);
    YHYDetailViewController *detail = [YHYDetailViewController new];
    detail.indexPath = indexPath;
    [self.navigationController pushViewController:detail animated:YES];
}
#pragma mark 搜索
- (void)souSuo:(UIButton *)sousuo{
  
    //NSLog(@"搜索按钮被点击了");
    
    YHYFindSearchViewController *find = [YHYFindSearchViewController new];
    [self.navigationController pushViewController:find animated:YES];
}


-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    
    if (scrollView == self.BigScrollView) {
        for (int i = 0; i < _naView.buttonArray.count; i++) {
            
        
            [UIView animateWithDuration:0.3 animations:^{
               
                UIButton * button = [_naView.buttonArray objectAtIndex:i];
                
                [button setTitleColor:HS forState:UIControlStateNormal];
                [button.titleLabel setFont:  [UIFont systemFontOfSize:AUTO_WIDTH*13.00]];
                
                
            }];
            
        }
        
        
        [UIView animateWithDuration:100 animations:^{
        
            
            UIButton *button=[_naView.buttonArray objectAtIndex:self.BigScrollView.contentOffset.x/self.view.frame.size.width];
            
            [button setTitleColor:GH forState:UIControlStateNormal];
            [button.titleLabel setFont:[UIFont systemFontOfSize:AUTO_WIDTH*15.00]];
            
          
        }];
    
    }
}

-(void)scrollViewDidScroll:(UIScrollView *)scrollView{

    [_naView.LineView mas_updateConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(_naView.mas_left).offset((KScreenWidth - 57.00* AUTO_WIDTH)/3/KScreenWidth * scrollView.contentOffset.x);
    }];

}


-(void) singinAction:(UIButton *) btn
{
    WUVippViewController *vipp=[[WUVippViewController alloc]init];
    [self.navigationController pushViewController:vipp  animated:YES];
}
@end
